package com.cw.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.cw.data.ConstantEnum;
import com.cw.data.Result;
import com.cw.pojo.TbItemCat;
import com.cw.service.ItemService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("itemCatController")
public class ItemCatController {

    @Reference
    private ItemService itemService;

    @RequestMapping("getItemInfo")
    @ResponseBody
    public Result getItemInfo(Long parentId) {

        try {

            List<TbItemCat> itemList = itemService.getItemInfo(parentId);

            return Result.result(ConstantEnum.SUCCESS).setData(itemList);
        }catch (Exception e) {

            e.printStackTrace();

            return Result.result(ConstantEnum.ERROR);
        }
    }

    @RequestMapping("getTypeId")
    @ResponseBody
    public Result getTypeId(Long id) {

        try {

            Long typeId = itemService.getTypeId(id);

            return Result.result(ConstantEnum.SUCCESS).setData(typeId);
        }catch (Exception e) {

            e.printStackTrace();

            return Result.result(ConstantEnum.ERROR);
        }
    }
}
